<?php

	// TITLE: Affiliated AUTO MODEL
	// FILE: scaffolding/model/affiliated.php
	// AUTHOR: AUTOGEN
	// CREATED: 2015/04/20 07:49:57
	// DESCRIPTION: 
	// REQUIREMENTS: 

	$createAffiliated = function($con, $affiliated) {
		$sql = 'INSERT INTO affiliated (person_id, organization_id, phone_id, email, start_date, end_date, status, is_employee) VALUES (';
		$sql .= $affiliated->getPersonId() . ', ';
		$sql .= $affiliated->getOrganizationId() . ', ';
		$sql .= $affiliated->getPhoneId() . ', ';
		$sql .= $affiliated->getEmail() . ', ';
		$sql .= $affiliated->getStartDate() . ', ';
		$sql .= $affiliated->getEndDate() . ', ';
		$sql .= $affiliated->getStatus() . ', ';
		$sql .= $affiliated->getIsEmployee() . ')';
		$sql .= ')';
		$result = mysqli_query($con, $sql);
		$id = ($result) ? mysqli_insert_id($con) : $result;
		mysqli_close($con);
		return $id;
	};

	$readAffiliated = function($con, $id) {
		$sql = 'SELECT * FROM affiliated WHERE id = ' . $id;
		$results = mysqli_query($con, $sql);
		mysqli_close($con);
		if ($results) {
			$result = mysqli_fetch_array($results);
			$affiliated = new Affiliated();
			$affiliated->setPersonId($dbio->select($readPerson(result[0])));
			$affiliated->setOrganizationId($dbio->select($readOrganization(result[1])));
			$affiliated->setPhoneId($dbio->select($readPhone(result[2])));
			$affiliated->setEmail(result[3]);
			$affiliated->setStartDate(result[4]);
			$affiliated->setEndDate(result[5]);
			$affiliated->setStatus(result[6]);
			$affiliated->setIsEmployee(result[7]);
		} else {
			$affiliated = false;
		}
		return $affiliated;
	};

	$updateAffiliated = function($con, $affiliated) {
		$sql = 'UPDATE affiliated SET ';
		$sql .= 'person_id = ' . $affiliated->getPersonId() . ', ';
		$sql .= 'organization_id = ' . $affiliated->getOrganizationId() . ', ';
		$sql .= 'phone_id = ' . $affiliated->getPhoneId() . ', ';
		$sql .= 'email = ' . $affiliated->getEmail() . ', ';
		$sql .= 'start_date = ' . $affiliated->getStartDate() . ', ';
		$sql .= 'end_date = ' . $affiliated->getEndDate() . ', ';
		$sql .= 'status = ' . $affiliated->getStatus() . ', ';
		$sql .= 'is_employee = ' . $affiliated->getIsEmployee() ;
		$sql .= 'WHERE id = ' . id;
		$result = mysqli_query($con, $sql);
		mysqli_close($con);
		return $result;
	};

	$deleteAffiliated = function($con, $id) {
		$sql = 'DELETE FROM affiliated WHERE person_id = ' . $id;
		$result = mysqli_query($con, $sql);
		mysqli_close($con);
		return $result;
	};

	$listAffiliated = function($con) {
		$sql = 'SELECT * FROM affiliated';
		$results = mysqli_query($con, $sql);
		mysqli_close($con);
		if ($results) {
			$affiliateds = array();
			while ($result = mysqli_fetch_array($results)) {
				$affiliated = new Affiliated();
				$affiliated->setPersonId($dbio->select($readPerson(result[0])));
				$affiliated->setOrganizationId($dbio->select($readOrganization(result[1])));
				$affiliated->setPhoneId($dbio->select($readPhone(result[2])));
				$affiliated->setEmail(result[3]);
				$affiliated->setStartDate(result[4]);
				$affiliated->setEndDate(result[5]);
				$affiliated->setStatus(result[6]);
				$affiliated->setIsEmployee(result[7]);
				$affiliateds[] = affiliated;
			}// end while
		} else {
			$affiliateds = false;
		}
		return $affiliateds;
	};

